using HKB.Common;
using HKB.Data.Dal;
using HKB.Data.Model;
using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
namespace HKB.Data.Bll
{
	public class UserGiftCardFestivalBll
	{
		private static UserGiftCardFestivalBll _instance = null;
		private readonly UserGiftCardFestivalDal dal = new UserGiftCardFestivalDal();
		public static UserGiftCardFestivalBll instance
		{
			get
			{
				if (UserGiftCardFestivalBll._instance == null)
				{
					UserGiftCardFestivalBll._instance = new UserGiftCardFestivalBll();
				}
				return UserGiftCardFestivalBll._instance;
			}
		}
		public DataTable GetDropDownListData(string strWhere)
		{
			System.Text.StringBuilder stringBuilder = new System.Text.StringBuilder();
			stringBuilder.Append("select FestivalName FieldValue,FestivalName FieldText");
			stringBuilder.Append(" FROM MBF_UserGiftCardFestival ");
			if (strWhere.Trim() != "")
			{
				stringBuilder.Append(" where " + strWhere);
			}
			return Conn.Query(stringBuilder.ToString(), new IDbDataParameter[0]).Tables[0];
		}
		public bool Exists(string FestivalName)
		{
			return this.dal.Exists(FestivalName);
		}
		public void Add(UserGiftCardFestivalModel model)
		{
			this.dal.Add(model);
		}
		public bool Update(UserGiftCardFestivalModel model)
		{
			return this.dal.Update(model);
		}
		public bool Delete(string FestivalName)
		{
			return this.dal.Delete(FestivalName);
		}
		public UserGiftCardFestivalModel GetModel(string FestivalName)
		{
			return this.dal.GetModel(FestivalName);
		}
		public UserGiftCardFestivalModel GetModelByCache(string FestivalName)
		{
			string cacheKey = "UserGiftCardFestivalModel_" + FestivalName;
			object obj = DataCache.GetCache(cacheKey);
			if (obj == null)
			{
				try
				{
					obj = this.dal.GetModel(FestivalName);
					if (obj != null)
					{
						int configInt = ConfigHelper.GetConfigInt("ModelCache");
						DataCache.SetCache(cacheKey, obj, System.DateTime.Now.AddMinutes((double)configInt), System.TimeSpan.Zero);
					}
				}
				catch
				{
				}
			}
			return (UserGiftCardFestivalModel)obj;
		}
		public DataSet GetList(string strWhere)
		{
			return this.dal.GetList(strWhere);
		}
		public DataSet GetList(int Top, string strWhere, string filedOrder)
		{
			return this.dal.GetList(Top, strWhere, filedOrder);
		}
		public System.Collections.Generic.List<UserGiftCardFestivalModel> GetModelList(string strWhere)
		{
			DataSet list = this.dal.GetList(strWhere);
			return this.DataTableToList(list.Tables[0]);
		}
		public System.Collections.Generic.List<UserGiftCardFestivalModel> DataTableToList(DataTable dt)
		{
			System.Collections.Generic.List<UserGiftCardFestivalModel> list = new System.Collections.Generic.List<UserGiftCardFestivalModel>();
			int count = dt.Rows.Count;
			if (count > 0)
			{
				for (int i = 0; i < count; i++)
				{
					UserGiftCardFestivalModel userGiftCardFestivalModel = new UserGiftCardFestivalModel();
					userGiftCardFestivalModel.FestivalName = dt.Rows[i]["FestivalName"].ToString();
					if (dt.Rows[i]["FestivalBegin"] != null && dt.Rows[i]["FestivalBegin"].ToString() != "")
					{
						userGiftCardFestivalModel.FestivalBegin = new System.DateTime?(System.DateTime.Parse(dt.Rows[i]["FestivalBegin"].ToString()));
					}
					if (dt.Rows[i]["FestivalEnd"] != null && dt.Rows[i]["FestivalEnd"].ToString() != "")
					{
						userGiftCardFestivalModel.FestivalEnd = new System.DateTime?(System.DateTime.Parse(dt.Rows[i]["FestivalEnd"].ToString()));
					}
					if (dt.Rows[i]["FestivalType"] != null && dt.Rows[i]["FestivalType"].ToString() != "")
					{
						userGiftCardFestivalModel.FestivalType = new int?(int.Parse(dt.Rows[i]["FestivalType"].ToString()));
					}
					list.Add(userGiftCardFestivalModel);
				}
			}
			return list;
		}
		public DataSet GetAllList()
		{
			return this.GetList("");
		}
		public DataSet GetListRowid(int Top, string strWhere, string filedOrder, params string[] selectField)
		{
			return this.dal.GetListRowid(Top, strWhere, filedOrder, selectField);
		}
		public DataSet PageOrderList(int PageSize, int PageIndex, string Orderfld, int OrderType, string strWhere)
		{
			int num = (PageIndex - 1) * PageSize;
			return Conn.ExecProSpPageOrder("MBF_UserGiftCardFestival", " " + num + "+ (ROW_NUMBER() OVER (ORDER BY FestivalName ASC)) rowid,*", PageSize, PageIndex, Orderfld, OrderType, strWhere);
		}
	}
}
